import axios from "axios";

// const local_fileServer_url = "http://api.door.vpclub.cn/file";
const local_fileServer_url = "http://175.24.116.12:9006/file";

export async function upload2KkFile(FileList) {
    let formData = new window.FormData();
    let url = 'http://kkfile.door.vpclub.cn/fileUpload';
    FileList.forEach(item => {
        //文件信息中raw才是真的文件
        formData.append('file', item.raw);
    });
    this.$http.post(url, formData).then((res) => {
        if (res.status === 200) {
            if (res.data.code === 1) {
                this.$message.error('上传失败,%s' % res.data.msg);
            } else {
                this.$emit('fMethod', "");
            }
        } else {
            this.$message.error('上传失败');
        }
    })
}

// ------------------------------------------------------------------------------------------------------------------------- upload2Bottole
export async function uploadBatch(FileList) {
    let formData = new FormData();
    let url = local_fileServer_url + '/upload/posts'
    FileList.forEach(item => {
        //文件信息中raw才是真的文件
        formData.append('files', item.raw);
    })
    const options = {
        method: 'POST',
        headers: {'content-type': 'multipart/form-data'},
        data: formData,
        url,
    };
    return axios(options).then(res => {
        if (res.code === 200) {
            return res.data;
        } else {
            this.$message.error('上传失败');
        }
    });
}

export async function uploadFile(file) {
    let formData = new FormData();
    formData.append('files', file);
    let url = local_fileServer_url + '/upload'
    const options = {
        method: 'POST',
        headers: {'content-type': 'multipart/form-data'},
        data: formData,
        url,
    };
    return axios(options).then(res => {
        if (res.code === 200) {
            return res.data;
        } else {
            this.$message.error('上传失败')
        }
    });
}

export async function uploadXlsFile(file) {
    let formData = new FormData();
    formData.append('files', file);
    let url = local_fileServer_url + '/upload/xls'
    const options = {
        method: 'POST',
        headers: {'content-type': 'multipart/form-data'},
        data: formData,
        url,
    };
    return axios(options).then(res => {
        if (res.code === 200) {
            return res.data;
        } else {
            this.$message.error('上传失败')
        }
    });
}

export async function uploadPicFile(file) {
    let formData = new FormData();
    formData.append('files', file);
    let url = local_fileServer_url + '/upload/pic'
    const options = {
        method: 'POST',
        headers: {'content-type': 'multipart/form-data'},
        data: formData,
        url,
    };
    return axios(options).then(res => {
        if (res.code === 200) {
            this.$message.success('上传成功')
        } else {
            this.$message.error('上传失败')
        }
        return res.data;
    });
}